package com.bootdo.common.controller;

import com.bootdo.common.service.impl.DocService;
import com.bootdo.common.utils.R;
import com.bootdo.form.JzForm;
import com.bootdo.form.PbAddForm;
import com.bootdo.system.domain.DocListDO;
import com.bootdo.system.domain.DocPbDO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/system/doc")
@Controller
public class DocController extends BaseController {
    private static final String prefix = "system/doc";

    @Autowired
    private DocService docService;

    /**
     * 跳转叫诊页面
     */
    @GetMapping("/doc")
    String doc() {
        return  prefix + "/doc";
    }

    /**
     * 获取当日叫诊数据
     */
    @ApiOperation(value="获取当日叫诊列表", notes="")
    @ResponseBody
    @GetMapping("/list")
    public List<DocListDO> list(String name) {
        return docService.list(getUserId(), name);
    }

    /**
     * 叫诊
     */
    @ApiOperation(value="叫诊", notes="")
    @ResponseBody
    @PostMapping("/jz")
    public R jz(JzForm JzForm) {
        try {
            return docService.jz(JzForm);
        }catch (Exception e){
            return R.error("叫诊失败，请联系管理员！");
        }
    }

    /**
     * 跳转到排班页面
     */
    @GetMapping("/pb")
    String pb() {
        return  prefix + "/pb";
    }

    /**
     * 获取排班数据
     */
    @ResponseBody
    @GetMapping("/list1")
    public List<DocPbDO> list1() {
        return docService.list1(getUserId());
    }

    @ResponseBody
    @PostMapping("/tingZhen")
    public R tingZhen(Long id) {
        return docService.tingZhen(id);
    }

    @ResponseBody
    @PostMapping("/kaiZhen")
    public R kaiZhen(Long id) {
        return docService.kaiZhen(id);
    }

    /**
     * 挑战到新增排班页面
     */
    @GetMapping("/pbAdd")
    String pbAdd() {
        return  prefix + "/pbAdd";
    }

    @ResponseBody
    @PostMapping("/pbAdd")
    R savePbAdd(PbAddForm docPbDO) {
        return docService.savePbAdd(getUserId(), docPbDO);
    }

}
